package com.cloudcc.mobile.adapter;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.cloudcc.cloudframe.adapter.CommonAdapter;
import com.cloudcc.cloudframe.adapter.ViewHolder;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.LoginDBModel;
import com.cloudcc.mobile.entity.LoginSPModel;

public class LoginHistoryAdapter extends CommonAdapter<LoginSPModel> {

	private OnHistoryItemClickListener mClickListener;

	public LoginHistoryAdapter(Context mContext) {
		super(mContext);
	}

	public void setOnClickListener(OnHistoryItemClickListener l) {
		this.mClickListener = l;
	}

	@Override
	public void convert(final ViewHolder holder, final LoginSPModel t) {

		TextView tvTitle = holder.getView(R.id.textview);
		ImageButton tvDelet = holder.getView(R.id.delet);

		tvTitle.setText(t.userName);
		tvTitle.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mClickListener != null) {
					mClickListener.onSelectedLogin(t, holder.getPostion());
				}
			}
		});
		tvDelet.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mClickListener != null) {
					mClickListener.onClickDeleteLogin(t, holder.getPostion());
				}
			}
		});

	}

	/**
	 * 登录历史监听事件
	 * 
	 * @author seven
	 * 
	 */
	public interface OnHistoryItemClickListener {
		/**
		 * 选中了 登录用户
		 * 
		 * @param t
		 * @param position
		 */
		void onSelectedLogin(LoginSPModel t, int position);

		/**
		 * 删除登录用户
		 * 
		 * @param t
		 * @param position
		 */
		void onClickDeleteLogin(LoginSPModel t, int position);
	}

	@Override
	public int getLayoutId() {
		return R.layout.login_item;
	}

}
